//
// Created by tcj on 2022/2/22.
//

#ifndef __SYLAR_MACRO_H__
#define __SYLAR_MACRO_H__

#include "string.h"
#include "assert.h"
#include "util.h"

#if defined __GNUC__ || defined __llvm__
#   define SYLAR_LICKLY(x)      __builtin_expect(!!(x),1)
#   define SYLAR_UNLICKLY(x)    __builtin_expect(!!(x),0)
#else
#   define SYLAR_LICKLY(x)      (x)
#   define SYLAR_UNLICKLY(x)    (x)
#endif

#define SYLAR_ASSERT(x) \
    if(SYLAR_UNLICKLY(!(x))){           \
        SYLAR_LOG_ERROR(SYLAR_LOG_ROOT()) <<"ASSERTON: " #x \
            <<"\nbacktrace:\n"                  \
            <<sylar::BacktraceTostring(100,2,"   ");       \
        assert(x);\
    }

#define SYLAR_ASSERT2(x,w) \
    if(SYLAR_UNLICKLY(!(x))){           \
        SYLAR_LOG_ERROR(SYLAR_LOG_ROOT()) <<"ASSERTON: "#x \
            <<"\n"<< w             \
            <<"\nbacktrace:\n"                  \
            <<sylar::BacktraceTostring(100,2,"   ");       \
        assert(x);\
    }



#endif //SERVER_FRAMEWORK_MACRO_H
